package com.peenongsaban.freelance.service;

import com.opensymphony.xwork2.ActionContext;
import com.peenongsaban.freelance.bean.RegisterBean;
import com.peenongsaban.freelance.dao.LoginDAO;
import com.peenongsaban.freelance.dao.impl.LoginDAOImpl;
import com.peenongsaban.freelance.utils.ConstantUtils;
import com.peenongsaban.freelance.utils.SessionUtils;

public class LoginService {

//	public RegisterBean getUserSession() {
//		RegisterBean bean = new RegisterBean();
//		bean.setUsername(ActionContext.getContext().getSession().get(ConstantUtils.SESSION_USERNAME).toString());
//		bean.getUser().setIdCard(ActionContext.getContext().getSession().get(ConstantUtils.SESSION_IDCARD).toString());
//
//		return bean;
//	}

	public boolean verifyLogin(String userName, String password) {
		boolean result = false;
		LoginDAO dao = new LoginDAOImpl();
		RegisterBean bean = dao.getUser(userName, password);
		if (bean != null) {
			result = true;
			setUserSession(bean);
		}
		return result;
	}
	
	public void setUserSession(RegisterBean bean){
		SessionUtils.setSession(ConstantUtils.SESSION_LOGIN, bean);
	}
	
	
	public void logout(){
		SessionUtils.removeSession(ConstantUtils.SESSION_LOGIN);

	}

}
